package com.itfreer.power.service.user;

import java.io.IOException;
import java.util.HashMap;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.utils.json.JsonUtils;
import com.itfreer.form.api.BaseRestService;
import com.itfreer.power.entity.user.UserAuthenticationEntity;

@Component
@Path("/userauthentication/")
public class RestUserAuthenticationService {
	
	/**
	 * 用户认证管理接口
	 */
	@Autowired
	private UserAuthenticationService userAuthenticationManage;

	/**
	 * 添加实体
	 * @param entity		添加实体
	 * @return
	 * @throws IOException 
	 */
	@POST
	@Path("/add")
	@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
	public UserAuthenticationEntity add(String data) throws IOException{
		HashMap<String, Object> args = BaseRestService.getRestParam(data);
		String entityJson = null;
		if (args != null && args.containsKey("entity") && args.get("entity") != null) {
			entityJson = args.get("entity").toString();
		}
		UserAuthenticationEntity entity = (UserAuthenticationEntity) JsonUtils.toBean(entityJson, UserAuthenticationEntity.class);
		return userAuthenticationManage.add(entity);
	}
	
	/**
	 * 更新实体
	 * @param entity		实体
	 * @return
	 * @throws IOException 
	 */
	@POST
	@Path("/update")
	@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
	public UserAuthenticationEntity update(String data) throws IOException{
		HashMap<String, Object> args = BaseRestService.getRestParam(data);
		String entityJson = null;
		if (args != null && args.containsKey("entity") && args.get("entity") != null) {
			entityJson = args.get("entity").toString();
		}
		UserAuthenticationEntity entity = (UserAuthenticationEntity) JsonUtils.toBean(entityJson, UserAuthenticationEntity.class);
		return userAuthenticationManage.update(entity);
	}
}